﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Security.Cryptography;

namespace TNCAddIn
{
    //用于与服务器进行同步的操作
    class Sync
    {
        //每30秒同步一次，操作包括更新操作及删除操作
        public void SyncWorker()
        {
            while(true)
            {
                try
                {
                    //更新所有内容
                    Opration op = new Opration();
                    op.updateAll(Items, Mail);
                }
                catch (Exception e) 
                {
                    if (e.Message.IndexOf("-3") == 0)
                    {
                        //密码不正确，输入
                        Password pass = new Password();
                        pass.Show();
                    }
                    else {
                        //MessageBox.Show(e.Message);
                    }
                }
                try
                {
                    //删除已删除的内容
                    Opration op = new Opration();
                    op.delete(Mail);
                }
                catch (Exception e)
                {
                    if (e.Message.IndexOf("-3") == 0)
                    {
                        //密码不正确，输入
                        Password pass = new Password();
                        pass.Show();
                    }
                }
                //更新间隔30秒
                Thread.Sleep(30000);
            }
        }

        public String Mail { get; set; }

        public Outlook.Items Items { get; set; }
    }
}
